<?php

namespace App\Admin\Actions\Grid\Row\SwtMachine;

use App\Admin\Forms\ReplenishForm;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Replenish extends RowAction
{
    protected $title = '进货';

    public function handle(Request $request)
    {
        $id = $request->get('machine_id');

        return $this->response()->redirect('machine/swt_replenish/create?machine_id='.$id);
    }

    /**
     * @return string|array|void
     */
    public function confirm()
    {
        return false;
    }

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [
            'machine_id'   => $this->row->id
        ];
    }

    protected function html()
    {
        return <<<HTML
            <a {$this->formatHtmlAttributes()}><i class="feather icon-user-plus text-warning"></i> <span class="text-warning">{$this->title}</span> &emsp;</a>
        HTML;
    }
}
